package com.newtouch.bxzs.syslog.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.syslog.config.MyLog;
import com.newtouch.bxzs.syslog.model.bo.LogErrorBO;
import com.newtouch.bxzs.syslog.model.vo.LogErrorVO;
import com.newtouch.bxzs.syslog.service.LogErrorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 异常日志控制器
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月18日</td>
 * <td>renyi</td>
 * <td>Update</td>
 * </tr>
 * </table>
 *
 * @author renyi
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "异常日志")
@RestController
@RequestMapping("/logError")
@SuppressWarnings("unchecked")
public class LogErrorController {

	private static final Log logger = LogFactory.getLog(LogErrorController.class);

	@Autowired
	private LogErrorService logErrorService;

	/**
	 * 查询异常日志列表，可选查询条件：开始时间，结束时间
	 *
	 * @param logErrorVO
	 *            异常日志查询vo
	 * @return 异常日志列表
	 */
	@ApiOperation("查询异常日志列表")
	@PostMapping("/getLogErrorList")
	@MyLog(systemFunctionName = "异常日志", systemFunctionUrl = "/logError/getLogErrorList", userOperationType = 4, userOperationSummary = "查询异常日志列表")
	public BaseResponse<IPage<LogErrorBO>> selectLogErrorList(@RequestBody LogErrorVO logErrorVO) {
		logger.info("查询异常日志列表");
		return RespGenerator.returnOK(logErrorService.selectLogErrorList(logErrorVO));
	}

	/**
	 * 通过日志id查询异常日志详情
	 *
	 * @param id
	 *            日志id
	 * @return 异常日志详细信息
	 */
	@ApiOperation("查询异常日志详情")
	@GetMapping("/getLogErrorDetail")
	@MyLog(systemFunctionName = "异常日志", systemFunctionUrl = "/logError/getLogErrorDetail", userOperationType = 4, userOperationSummary = "查询异常日志详情")
	public BaseResponse<LogErrorBO> getLogErrorDetail(
			@RequestParam(value = "errorLogId") @ApiParam(value = "异常日志ID", required = true) String errorLogId) {
		logger.info("查询异常日志详情");
		return RespGenerator.returnOK(logErrorService.getLogErrorDetail(errorLogId));
	}

}
